package com.beemans.common.utils

import android.annotation.SuppressLint
import android.location.LocationManager
import com.blankj.utilcode.util.DeviceUtils
import com.blankj.utilcode.util.PhoneUtils
import com.hjq.permissions.Permission
import com.tiamosu.fly.utils.locationManager

/**
 * @author tiamosu
 * @date 2021/3/12
 */
object TelephoneUtils {

    /**
     * 手机是否开启位置服务，如果没有开启那么所有app将不能使用定位功能
     */
    fun isLocServiceEnable(): Boolean {
        val gps = locationManager?.isProviderEnabled(LocationManager.GPS_PROVIDER) ?: false
        val network = locationManager?.isProviderEnabled(LocationManager.NETWORK_PROVIDER) ?: false
        return gps || network
    }

    @SuppressLint("MissingPermission")
    fun getIMEI(): String? {
        return if (PermissionHelper.isGranted(Permission.READ_PHONE_STATE)) {
            PhoneUtils.getIMEI()
        } else {
            DeviceUtils.getAndroidID()
        }
    }
}